/**
 * OCLC, Inc.
 *
 * OCLC proprietary information: the enclosed materials contain
 * proprietary information of OCLC Online Computer Library Center, Inc.
 * and shall not be disclosed in whole or in any part to any third party
 * or used by any person for any purpose, without written consent of
 * OCLC, Inc.  Duplication of any portion of these materials shall
 * include this legend.
 *
 * FaceBookClientTest
 *
 * @author Jackie Gleason
 * @version 1.0
 */
package org.sociald.wave.common.groovy

import org.sociald.facebook.client.FacebookClient
import org.junit.Before
import com.google.code.facebookapi.FacebookJsonRestClient
import org.json.JSONArray
import org.junit.After
import org.junit.Test
import org.junit.Assert

class FacebookClientTest {
    FacebookClient client
    String messageText = 'Message 1'
    @Before
    public void buildUp(){
        FacebookJsonRestClient.metaClass.fql_query = {String query->
            return new JSONArray(query)
        }
    }
    @After
    public void tearDown() {
        GroovySystem.metaClassRegistry.removeMetaClass(FacebookJsonRestClient)
    }
    @Test
    public void testGetMessagesSingleMessage(){        
        FacebookClient.metaClass.getMessagesQuery= {String id, String time ->
            return "[{'message':'${messageText}'}]"
        }
        client = new FacebookClient()
        client.setClient "Ser"
        List<String> response= client.getMessagesByDate('id',(Long)100)
        Assert.assertTrue("Make sure there is only one message",response.size().equals(1))
        Assert.assertEquals("Make sure the value is as expected",messageText,response.get(0))
        GroovySystem.metaClassRegistry.removeMetaClass(FacebookClient)
    }
}
